__version__ = "1.1.0"
import os
import pandas as pd
import logging

from Tools.osTools.osTools import get_dir_bcp_name
from Tools.mysqltools.MysqlTool import MysqlTool
from Tools.logtools.logtools import logfile_hander, console_handler
from Tools.conftools.configtools import demo_config


logger = logging.getLogger(__name__)
logger.setLevel(level=logging.INFO)
logger.addHandler(logfile_hander())
logger.addHandler(console_handler())


cfg = demo_config()


#2024_12_2 shp将 070400 scv写入表格
def Get_bcp_070400(bcps):
    dfs = []
    print(range(len(bcps)))
    for i in range(len(bcps)):
        df = pd.read_csv(bcps[i][0],sep="\t",names=["电子取证采集目标编号","软件类型","用户ID","账号","昵称","对方用户ID","对方账号","对方昵称","本地动作","交易时间","价格","交易状态","详细描述","交易记录ID","删除状态","删除时间","账号类型","交易币种","支付工具类型","支付工具用户ID","支付工具账号","支付工具的真实姓名","收货地点名称","收货详细地址","收货地址经度","收货地址纬度","收货地址海拔","收货人姓名","收货人联系方式","当前余额","购买数量","店铺ID","商品ID","物流单号","物流公司","运费","发票类型","发票抬头","公司税号","发票内容","拼单时间","手续费/服务费"])
        #dfs.append (df)

        mysql = dict(cfg["dan_ji"]["mysql"]["database"][0])
        db = MysqlTool(ip=cfg["dan_ji"]["ip"], database=mysql["dbname"], user=mysql["user"], pwd=mysql["pwd"],
                       port=cfg["dan_ji"]["mysql"]["port"], )
        #rows = db.query_all("select  * from nrlj_detail_user_shopping_detailed ndusd ")

    result=pd.concat(dfs)

    current_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    os.chdir(os.path.dirname(current_directory)+'/Downloads')

    with pd.ExcelWriter('my_file.xlsx') as writer:
        result.to_excel(writer , index=False,sheet_name=f'Sheet')

#由身份证查 bcp包,身份证自行修改
def bcpfind(num_id = "all"):
    bcps=[]
    mysql = dict(cfg["dan_ji"]["mysql"]["database"][0])
    db = MysqlTool(ip=cfg["dan_ji"]["ip"], database=mysql["dbname"], user=mysql["user"], pwd=mysql["pwd"],
                   port=cfg["dan_ji"]["mysql"]["port"], )
    if num_id == "all":
        rows = db.query_all("SELECT PHONE_PATH,SYS_USER_NAME,user_id from nrlj_phone_manage where status = 'over'")
    else:
        rows = db.query_all("SELECT PHONE_PATH,SYS_USER_NAME,user_id from nrlj_phone_manage WHERE ID_NUM in (" + num_id + ") and e status = 'over'")
    for row in rows:
        bcp_temp = []
        bcp_path = row["PHONE_PATH"].split('/')[6]
        bcps.append(bcp_path)
        #bcp_temp.append(bcp_path)
        #bcp_nameid = row["user_id"]
        #bcp_temp.append(bcp_nameid)
        #bcps.append(bcp_temp)
    return bcps

if __name__ == '__main__':
    #bcps_find = bcpfind('\'65292319851020498X\'')
    bcps_find = bcpfind()
    #print(bcps_find)
    #progress_bar()
    dir = '/media/dhz/smbmounts/smb-share:server=192.168.20.20,share=share/bcp'
    bcps_070400 =  get_dir_bcp_name(dir,'_070400',bcps_find)
    #print (bcps_070400)
    #Get_bcp_070400(bcps_070400)
    #update_bcp(bcps)
    #print(df_tsv)
